#include "FreeCamera.h"

FreeCamera::FreeCamera()
{
}

FreeCamera::~FreeCamera()
{
}
void FreeCamera::GetViewMatrix(D3DXMATRIX& a_outViewMat)
{
	//Reset
	m_up = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
	m_look = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
	m_right = D3DXVECTOR3(1.0f, 0.0f, 0.0f);

	//Apply yaw rotation to look and right axis
	D3DXMATRIX yawMatrix;
	D3DXMatrixRotationAxis(&yawMatrix, &m_up, m_yawPitchRoll.x);
	D3DXVec3TransformCoord(&m_look, &m_look, &yawMatrix);
	D3DXVec3TransformCoord(&m_right, &m_right, &yawMatrix);

	//Apply pitch to look and up axis
	D3DXMATRIX pitchMatrix;
	D3DXMatrixRotationAxis(&pitchMatrix, &m_right, m_yawPitchRoll.y);
	D3DXVec3TransformCoord(&m_look, &m_look, &pitchMatrix);
	D3DXVec3TransformCoord(&m_up, &m_up, &pitchMatrix);

	//Apply roll to right and up axis
	D3DXMATRIX rollMatrix;
	D3DXMatrixRotationAxis(&rollMatrix, &m_look, m_yawPitchRoll.z);
	D3DXVec3TransformCoord(&m_right, &m_right, &rollMatrix);
	D3DXVec3TransformCoord(&m_up, &m_up, &rollMatrix);

	D3DXMatrixIdentity(&a_outViewMat);
	a_outViewMat._11 = m_right.x;
	a_outViewMat._21 = m_right.y;
	a_outViewMat._31 = m_right.z;

	a_outViewMat._12 = m_up.x;
	a_outViewMat._22 = m_up.y;
	a_outViewMat._32 = m_up.z;

	a_outViewMat._13 = m_look.x;
	a_outViewMat._23 = m_look.y;
	a_outViewMat._33 = m_look.z;

	a_outViewMat._41 = D3DXVec3Dot(&m_eyePos, &m_right);
	a_outViewMat._42 = D3DXVec3Dot(&m_eyePos, &m_up);
	a_outViewMat._43 = D3DXVec3Dot(&m_eyePos, &m_look);
}
void FreeCamera::Update(float a_dt)
{
}
